# from upload import shoot_flag
#
# shoot_flag=0

# from PIL import Image
# from PIL.ExifTags import TAGS
#
#
# def get_exif_data(fname):
#     """Get embedded EXIF data from image file."""
#     ret = {}
#     try:
#         img = Image.open(fname)
#         if hasattr(img, '_getexif'):
#             exifinfo = img._getexif()
#             if exifinfo != None:
#                 for tag, value in exifinfo.items():
#                     decoded = TAGS.get(tag, tag)
#                     ret[decoded] = value
#     except IOError:
#         print('IOERROR ' + fname)
#     return ret




from pyexiv2 import Image
def get_exif(file):
    img = Image(file)
    info1=img.read_exif()		# 读取 EXIF 类型的元数据，这会返回一个字典
    print(info1)
    #{'Exif.Image.DateTime': '2019:06:23 19:45:17', 'Exif.Image.Artist': 'TEST', 'Exif.Image.Rating': '4', ...}
    img.read_iptc()
    #{'Iptc.Envelope.CharacterSet': '\x1b%G', 'Iptc.Application2.ObjectName': 'TEST', 'Iptc.Application2.Keywords': 'TEST', ...}
    img.read_xmp()
    #{'Xmp.dc.format': 'image/jpeg', 'Xmp.dc.rights': 'lang="x-default" TEST', 'Xmp.dc.subject': 'TEST', ...}
    img.close()			# 操作完之后，记得关闭图片，释放内存


if __name__ == '__main__':
    fileName = r'E:\program\PycharmProjects\web\teamonitor-master\static\images\2023-4-13\(1).jpg'
    # exif = get_exif_data(fileName)
    # print(exif)
    get_exif(fileName)
